package fr.cyol.android.levaldesetoiles;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ImageAdapter extends BaseAdapter {
    private Context mContext;
	private final Integer[] nomsDesEtres;
	private final Integer[] imagesDesEtres;

    public ImageAdapter(Context c, Integer[] nomsDesEtres, Integer[] imagesDesEtres) {
        mContext = c;
        this.nomsDesEtres = nomsDesEtres;
        this.imagesDesEtres = imagesDesEtres;
    }

    public int getCount() {
        return imagesDesEtres.length;
    }

    public Object getItem(int position) {
        return null;
    }

    public long getItemId(int position) {
        return 0;
    }

    // create a new ImageView for each item referenced by the Adapter
    public View getView(int position, View convertView, ViewGroup parent) {
        Resources res = mContext.getResources();

		LayoutInflater inflater = (LayoutInflater) mContext
			.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 
		View gridView;
 
		if (convertView == null) {
 
			gridView = new View(mContext);
 
			// get layout from mobile.xml
			gridView = inflater.inflate(R.layout.grid_img_txt, null);
 
			// set value into textview
			TextView textView = (TextView) gridView
					.findViewById(R.id.grid_item_label);
			textView.setText(res.getText(nomsDesEtres[position]));
 
			
			Drawable img = res.getDrawable(imagesDesEtres[position]);
			textView.setCompoundDrawablesWithIntrinsicBounds(null, img, null, null);
 
		} else {
			gridView = (View) convertView;
		}
 
		return gridView;
    }
    
}
